#!/bin/sh

tar -xvf pcre-8.35.tar.gz
cd pcre-8.35
./configure --prefix=/usr || exit 1
make || exit 1
make install || exit 1
cd ..
rm -rf pcre-8.35

tar -zxf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure --prefix=/usr/local/nginx || exit 1
make || exit 1
make install || exit 1
cd ..
rm -rf nginx-1.12.0

sed -i -e '/^\s*error_page/,+3d' -e 'N;N;s/^\(\s*location \/ {\).*/\
\1\
            proxy_pass http:\/\/desthost;\
            proxy_set_header X-Real-IP \$remote_addr;\
            proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;/' /usr/local/nginx/conf/nginx.conf
